﻿using System.Data;

namespace SpiderMaster.AspNet.TradingSystem
{
    /// <summary> <see cref="DataTable"/> Extensions.
    /// </summary>
    public static class DataTableExtensions
    {
        /// <summary>
        /// Returns the first row of the Instance Instance.
        /// </summary>
        /// <typeparam name="T">The DataRow you wish to invoke the result as.</typeparam>
        /// <typeparam name="TInner">The strongly named DataTable class.</typeparam>
        /// <param name="Table">Input Data.</param>
        /// <returns>The result or null.</returns>
        public static T GetFirstRow<T, TInner>(this TInner Table)
            where T : DataRow
            where TInner : DataTable
        {
            TInner ThisTable = Table as TInner;

            if (ThisTable != null && ThisTable.Rows.Count > 0)
                return (T)ThisTable.Rows[0] as T;
            else
                return null;
        }
    }
}
